﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using LGSVR.Common;
using LGSVR.BLL.Program;

namespace LGSVR_WEB.sys
{
    public partial class UserCardGroupMain : LGSVR.Common.DataBasePage   
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            //if (!IsPostBack)
            //{
                string strWhere = string.Empty;
                if (!string.IsNullOrEmpty(Request["UserID"]))
                {
                    lblmessageCard.Text = "<span>当前选择用户为" + Request["UserName"] + "，请进行权限配置。</span>";
                    hdUserID.Value = Request["UserID"];
                    hdUserName.Value = Request["UserName"];
                    strWhere = " and UserID = '" + Request["UserID"] + "'";
                    gvDataBind(strWhere);
                }
                else
                {
                    lblmessageCard.Text = "<span style=\"color: #FF0000\">请先在左边选择用户，再进行权限配置。</span>";
                }
            //}
        }
        private void gvDataBind(string strWhere)
        {
            DataTable dt;
            int totalRS;
            int pageIndex;
            if (!string.IsNullOrEmpty(Request.QueryString["pg"]) && Utils.IsNumber(Request.QueryString["pg"]))
            {
                pageIndex = int.Parse(Request.QueryString["pg"]);
            }
            else
            {
                pageIndex = 1;
            }

            dt = GetList("VuserCardGroup", " CardGroupID Asc ", strWhere, pageIndex, PageSize, out totalRS);
            rptBody.DataSource = dt;
            rptBody.DataBind();
            SplitHtmlCode = Split.GetHtmlCode("UserCardGroupSet.aspx", 8, pageIndex, PageSize, totalRS);

            lblmessageCard.Text = "符合条件的记录，共有" + totalRS.ToString() + "条。当前所选用户为：" + Request["UserName"] + "。"; 
        }
       
       

        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            
            bool isTrue = Delete("userCardGroup", Request["chkId"]);
            if (isTrue)
            {
                MsgContent = ShowMessage("恭喜您，删除成功！", MessageType.Success, false, true);
                NoRefresh();
            }
            else
            {
                MsgContent = ShowMessage("对不起,操作失败，请重试。", MessageType.Error, false, true);
            }
        }

        protected void lbtnUnable_Click(object sender, EventArgs e)
        {
            bool isTrue = UpdateState("userCardGroup", false, Request["chkId"]);
            if (isTrue)
            {
                MsgContent = ShowMessage("恭喜您，停用成功！", MessageType.Success, false, true);
                NoRefresh();
            }
            else
            {
                MsgContent = ShowMessage("对不起,操作失败，请重试。", MessageType.Error, false, true);
            }
        }

    }
}